package cn.ecut.dzy.day1;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: JavaWeb
 * @description:
 * @author: DingZhenYun
 * @create: 2021-07-26 21:08
 **/

public class HelloServlet2 extends HttpServlet {
    @Override
    public void init() throws ServletException {
        super.init();
        System.out.println("重写了init初始化方法,做了一些工作");
    }

    /*
         doGet（）在get请求的时候调用
         */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("HelloServlet2 的doGet方法");
        // 也可以使用.ServletConfig 是每个Servlet 程序创建时，就创建一个对应的ServletConfig对象。
        ServletConfig servletConfig = getServletConfig();
        System.out.println(servletConfig);

        //获取初始化参数init-param
        System.out.println("初始化参数username的值是;" + servletConfig.getInitParameter("username"));
        System.out.println("初始化参数url的值是;" + servletConfig.getInitParameter("url"));
    }

    /*
    doPost（）在post请求的时候调用
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("HelloServlet2 的doGet方法");
    }
}
